﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Barbar.Colonization.Model {
  public class RawMaterials {
    private Hashtable m_RawMaterials = new Hashtable();

    public int this[IRawMaterialType type] {
      get {
        EnsureRawMaterialType(type);
        return (int)m_RawMaterials[type];
      }
    }

    private void EnsureRawMaterialType(IRawMaterialType type) {
      if (!m_RawMaterials.ContainsKey(type))
        m_RawMaterials.Add(type, 0);
    }

    private void Change(IRawMaterialType type, int count) {
      EnsureRawMaterialType(type);
      int currentValue = (int)m_RawMaterials[type];
      currentValue += count;
      m_RawMaterials[type] = currentValue;
    }

    public void Add(IRawMaterialType type, int count) {
      if (type == null)
        throw new ArgumentNullException("type");
      if (count < 0)
        throw new ArgumentOutOfRangeException("count");

      Change(type, count);
    }

    public void Remove(IRawMaterialType type, int count) {
      if (type == null)
        throw new ArgumentNullException("type");
      if (count<0)
        throw new ArgumentOutOfRangeException("count");

      Change(type, -count);
    }
  }
}
